﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
//using _1061102_1061114_1061129_1061132_1061141.Models;
using PagedList;
using BanDTBLL;
using _1061102_1061114_1061129_1061132_1061141.Models;
namespace _1061102_1061114_1061129_1061132_1061141.Controllers
{
    public class LoaiSanPhamController : Controller
    {
        //
        // GET: /LoaiSanPham/
        ban_dien_thoai_dbEntities store = new ban_dien_thoai_dbEntities();
        public ActionResult Index()
        {
            return RedirectToAction("ListLoaiSanPham");
        }

        public ActionResult ListLoaiSanPham(int? page)
        {
            var ListSP = store.loai_san_pham.OrderBy(a => a.ma);

            int pageSize = 4;
            int pageNumber = (page ?? 1);
            return View(ListSP.ToPagedList(pageNumber, pageSize));
        }

        public ActionResult ThemLoaiSanPham()
        {
            return View();
        }

        [HttpPost]
        public ActionResult ThemLoaiSanPham(LoaiSanPham Model)
        {
            loai_san_pham lsp = new loai_san_pham();
            lsp.tenLoai = Model.tenloai;

            store.loai_san_pham.AddObject(lsp);
            store.SaveChanges();

            return RedirectToAction("Index");
        }


        public ActionResult EditLSP(int id)
        {
            var lsp = store.loai_san_pham.Where(a => a.ma == id).FirstOrDefault();
            LoaiSanPham LoaiSP = new LoaiSanPham();
            LoaiSP.ma = lsp.ma;
            LoaiSP.tenloai = lsp.tenLoai;

            return View(LoaiSP);
        }

        [HttpPost]
        public ActionResult EditLSP(LoaiSanPham Model)
        {
            var lsp = store.loai_san_pham.Where(a => a.ma == Model.ma).FirstOrDefault();
            lsp.tenLoai = Model.tenloai;
            store.SaveChanges();

            return RedirectToAction("Index");

        }

    }
}
